<script>
	import {
		isEmpty
	} from '@/utils/common.js'
	import Vue from 'vue'

	export default {
		globalData: {
			btDevices: [],
			platform: 'ios',
		},
		onLaunch: function() {
			// console.log('App Launch')
			this.getDeviceDetail()
			this.getUserDetail()
		},
		onShow: function() {
			// console.log('App OnShow')
		},
		onHide: function() {
			// console.log('App Hide')
		},
		methods: {
			// 获取设备信息
			getDeviceDetail() {
				var self = this
				uni.getSystemInfo({
					success: function(res) {
						self.globalData.platform = res.platform;
					}
				})
			},
			// 获取个人信息
			getUserDetail() {
				if (!this.$store.getters.token) { // 无token，重新登陆
					uni.redirectTo({
						url: '/pages/login/index',
					})
					return
				}
				this.$api.getUserApi()
					.then((res) => {
						if (res.status === 200) {
							this.$store.dispatch('setUser', res.resultParam.currentUser.user)
						} else { // 获取个人信息失败重新登陆
							uni.redirectTo({
								url: '/pages/login/index',
							})
							throw new Error('获取个人信息失败重新登陆')
						}
						return this.$api.getParentApi()
					})
					.then(result => {
						this.$store.dispatch('setSite', result.resultParam.parent)
					})
					.catch((err) => {
						this.$store.dispatch('setToken', '')
						console.log(err)
					})
			}
		}
	}
</script>

<style>
	@import url("/static/font/iconfont.css");

	page {
		background-color: #F7F7F7;
	}

	/* 限制行数 */
	.limit-text-5 {
		display: -webkit-box;
		-webkit-box-orient: vertical;
		-webkit-line-clamp: 5;
		overflow: hidden;
		text-align: justify;
	}

	.limit-text-4 {
		display: -webkit-box;
		-webkit-box-orient: vertical;
		-webkit-line-clamp: 4;
		overflow: hidden;
		text-align: justify;
	}

	.limit-text-3 {
		display: -webkit-box;
		-webkit-box-orient: vertical;
		-webkit-line-clamp: 3;
		overflow: hidden;
		text-align: justify;
	}

	.limit-text-2 {
		display: -webkit-box;
		-webkit-box-orient: vertical;
		-webkit-line-clamp: 2;
		overflow: hidden;
		text-align: justify;
	}

	.limit-text-1 {
		display: -webkit-box;
		-webkit-box-orient: vertical;
		-webkit-line-clamp: 1;
		overflow: hidden;
		text-align: left;
	}
</style>
